﻿Public Class EmpleadoDelMes 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub EmpleadosdelmesBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles EmpleadosdelmesBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.EmpleadosdelmesBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub EmpleadoDelMes_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.cargos' table. You can move, or remove it, as needed.
        Me.CargosTableAdapter.Fill(Me.DbFireAndIceDataSet.cargos)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleadosdelmes' table. You can move, or remove it, as needed.
        Me.EmpleadosdelmesTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdelmes)



    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If IdempleadoLookUpEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdempleadoLookUpEdit, "Debe ingresar un Empleado")
            Return
        End If
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)

        ''Dim dat As DateTime = FechaDateEdit.EditValue
        'If Not IsDBNull(FechaDateEdit) Then

        '    ErrorProvider1.SetError(FechaDateEdit, "Debe ingresar una Fecha")
        '    Return
        'End If
        'ErrorProvider1.SetError(FechaDateEdit, Nothing)

        If BonoTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(BonoTextEdit, "Debe ingresar un bono")
            Return
        End If
        ErrorProvider1.SetError(BonoTextEdit, Nothing)


        'EmpleadosdelmesBindingNavigatorSaveItem.PerformClick()
        'Mostrar()
        Try
            EmpleadosdelmesBindingNavigatorSaveItem.PerformClick()
            AlertControl1.AppearanceCaption.ForeColor = Color.Green
            AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
            Mostrar()
        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No se pudo guardar el registro")
        End Try





    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(FechaDateTimePicker, Nothing)
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
    

        Mostrar()
        Me.EmpleadosdelmesTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdelmes)
    End Sub

    



    Private Sub BonoTextEdit_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True

            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")
            BonoTextEdit.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")
            BonoTextEdit.Focus()

        Else
            e.Handled = False

        End If
    End Sub


    Private Sub IdempleadoLookUpEdit_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IdempleadoLookUpEdit.EditValueChanged
        If Not IsDBNull(IdempleadoLookUpEdit) Then  'si no es nulo el lookupedit
            TextEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("nombre")
            TextEdit2.EditValue = IdempleadoLookUpEdit.GetColumnValue("apellido")
            '  TextEdit3.EditValue =
            PictureEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("fotografia1")
            IdcargoLookUpEdit.EditValue = IdempleadoLookUpEdit.GetColumnValue("idcargo")
        End If
    End Sub
End Class